package cn.sdut.training.web.action;

import java.util.List;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;

import cn.sdut.training.domain.Oj;
import cn.sdut.training.service.TrainingService;

public class OjAction extends ActionSupport{

	private static final long serialVersionUID = 1986623025186552093L;

	private Long id;
	private Oj oj;
	private List<Oj> ojList;
	private Long[] idList;//批量删除
	
	@Resource
	private TrainingService trainingService;
	
	
	//-------------------------------------------------------------
	/**
	 * 转到保存界面
	 * @return
	 */
	public String toSavePage(){
		return "toSavePage";
	}
	
	/**
	 * 执行保存的方法，需要设置专业的学院信息
	 * @return
	 */
	public String save(){
		trainingService.saveOj(oj);
		return "toList";
	}
	
	/**
	 * 转到列表页面
	 * @return
	 */
	public String toListPage(){
		ojList = trainingService.findAllOj();
		return "toListPage";
	}
	
	/**
	 * 执行删除操作
	 * @return
	 */
	public String delete(){
		for(Long id:idList){
			trainingService.deleteOj(id);
		}
		return "toList";
	}
	
	/**
	 * 转到编辑页面
	 * @return
	 */
	public String toEditPage(){
		oj = trainingService.getOjById(id);
		return "toEditPage";
	}
	
	/**
	 * 执行更新操作
	 * @return
	 */
	public String update(){
		trainingService.updateOj(oj);
		return "toList";
	}

	//-----------------------------------
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Oj getOj() {
		return oj;
	}

	public void setOj(Oj oj) {
		this.oj = oj;
	}

	public List<Oj> getOjList() {
		return ojList;
	}

	public void setOjList(List<Oj> ojList) {
		this.ojList = ojList;
	}

	public Long[] getIdList() {
		return idList;
	}

	public void setIdList(Long[] idList) {
		this.idList = idList;
	}
	
	
}
